package com.xiaofengstu.mcams.web.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaofengstu.mcams.dto.UserDTO;
import com.xiaofengstu.mcams.util.RedisUtils;
import com.xiaofengstu.mcams.util.SerializeUtils;
import com.xiaofengstu.mcams.web.entity.TUser;
import com.xiaofengstu.mcams.web.mapper.TUserMapper;
import com.xiaofengstu.mcams.web.service.TUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author fengzeng
 * @since 2022-05-07
 */
@Service
@RequiredArgsConstructor
@CacheConfig(cacheNames = "user")
public class TUserServiceImpl extends ServiceImpl<TUserMapper, TUser> implements TUserService {

  private final TUserMapper userMapper;
  private final RedisUtils redisUtils;



  @Override
  public Page<UserDTO> getUserList(Integer page, Integer size) {
    Page<UserDTO> userList = userMapper.getUserList(new Page<UserDTO>(page, size));
    userList.setTotal(userMapper.getUserCount());
    return userList;
  }

  //按分类查询品牌时进行缓存，缓存名称是brand-category，键是分类id
  @Cacheable(cacheNames = "user-userInfo",key = "T(Integer).valueOf(#campusId)")
  @Override
  public List<UserDTO> searchBy(String username, Integer campusId, Integer deptId) {
    return userMapper.searchBy(username,campusId,deptId);
  }


}
